<!--管理员查看毕设阶段列表-->
<style>
	.yanse {
		width: 20px;
		height: 20px;
		display: inline-block;
		line-height: 20px;
	}
	
	.input-group {
		margin-bottom: 20px;
	}
	
	.xiaofangkuai {
		display: inline-block;
	}
	
	.demo-input {
		padding-left: 10px;
		height: 38px;
		min-width: 262px;
		line-height: 38px;
		border: 1px solid #e6e6e6;
		background-color: #fff;
		border-radius: 2px;
	}
</style>

<h3 class="text-center" style="margin-bottom: 20px;">毕设阶段维护(修改之后需要重启服务器)</h3>

<table class="table table-striped table-bordered table-hover">

</table>

<!-- 修改课题模态框 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title" id="myModalLabel">修改毕设阶段</h4>
			</div>
			<div class="modal-body">
				<div class="input-group">
					<span class="input-group-addon" id="kaishishijian1">毕设阶段</span>
					<input id="stage1" type="text" class="form-control" aria-describedby="kaishishijian" disabled="disabled">
				</div>
				<div class="input-group">
					<span class="input-group-addon" id="kaishishijian1">开始时间</span>
					<input type="text" class="demo-input" id="start1" placeholder="请选择日期" />
				</div>
				<div class="input-group">
					<span class="input-group-addon" id="jieshushijian1">结束时间</span>
					<input type="text" class="demo-input" id="end1" placeholder="请选择日期" />
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" data-dismiss="modal" id="stage_ok_xiugai">确定修改</button>
			</div>
		</div>
	</div>
</div>

<script>
	//初始化日期编辑器
	laydate.render({
		elem: '#start1',
		type: 'datetime'
	});
	laydate.render({
		elem: '#end1',
		type: 'datetime'
	});

	var myajax = $.ajax({
		xhrFields: {
			withCredentials: true
		},
		type: 'get',
		url: getFullURL('admin/get-stage'),
		data: {},
		dataType: 'json',
		success: function(data) {
			console.log(data)
			if(data.status == 0) {
				$('.table').html("");
				var str = `
					<thead><tr>
						<th col style="width: 25%">毕设阶段</th>
						<th col style="width: 30%">开始时间</th>
						<th col style="width: 30%">结束时间</th>
						<th col style="width: 15%">操作</th>
					</tr></thead>
				`;
				$('.table').append(str);
				$.each(data.list, function(i, n) {
					var val = '';
					if(n.stage == 1) {
						val = "开题报告阶段";
					} else if(n.stage == 2) {
						val = "任务书阶段";
					} else if(n.stage == 3) {
						val = "终稿阶段";
					} else if(n.stage == 4) {
						val = "定稿阶段";
					}
					var str = `<tr>
						<td>` + val + `</td>
						<td>` + n.start + `</td>
						<td>` + n.end + `</td>
						<td>
							<div class="btn-group" role="group" aria-label="...">
								<button type="button" class="btn btn-default stage_xiugai" value="` + n.stage + `">修改</button>
							</div>
						</td></tr>
					`;
					$('.table').append(str);
				})
			} else {
				console.log('无数据或请求失败')
			}
		},
		error: function(err) {
			alert("请求异常，请重新登录！", function() {
				$(location).attr('href', './login.html');
			})
		}
	})

	$.when(myajax).done(function() {
		$('.stage_xiugai').click(function() {
			$.session.set("stage", $(this).val());
			$.ajax({
				xhrFields: {
					withCredentials: true
				},
				type: 'get',
				url: getFullURL('admin/sel-stage'),
				data: {
					stage: $(this).val()
				},
				dataType: 'json',
				success: function(data) {
					console.log(data)

					if(data.status == 0) {
						var val = '';
						if(data.value.stage == 1) {
							val = "开题报告阶段";
						} else if(data.value.stage == 2) {
							val = "任务书阶段";
						} else if(data.value.stage == 3) {
							val = "终稿阶段";
						} else if(data.value.stage == 4) {
							val = "定稿阶段";
						}

						$('#stage1').val(val);
						$('#start1').val(data.value.start);
						$('#end1').val(data.value.end);

						$('#myModal').modal({
							keyboard: true,
							show: true
						})
					}
				},
				error: function(err) {
					alert("请求异常，请重新登录！", function() {
						$(location).attr('href', './login.html');
					})
				}
			})
		})
	})

	$('#stage_ok_xiugai').click(function() {
		$.ajax({
			xhrFields: {
				withCredentials: true
			},
			type: 'post',
			url: getFullURL('admin/update-stage'),
			data: {
				stage: $.session.get("stage"),
				start: $('#start1').val(),
				end: $('#end1').val()
			},
			dataType: 'json',
			success: function(data) {
				console.log(data)
				if(data.status == 0) {
					alert("修改成功！");
					setTimeout(function() {
						$('.center').html('');
						$('.center').load('./adminStage.html');
					}, 300)
				}
			},
			error: function(err) {
				alert("请求异常，请重新登录！", function() {
					$(location).attr('href', './login.html');
				})
			}
		})
	})
</script>